﻿$(function() {
    JSUtility.param.ClassName = "OA.Bll.Project.ProjectEmployeeMappingPresenter";
    JSUtility.param.Options["InternalType"] = "0";
    autoResize({ dataGrid: '#Grid', callback: Initlist });

    JSUtility.window_edit = $('#Add').window({
        iconCls: 'icon-add',
        zIndex: 1000,
        draggable: true,
        resizable: false,
        shadow: true,
        inline: true,
        modal: true,
        title: '项目人员信息',
        collapsible: false,
        minimizable: false,
        maximizable: false,
        closable: true,
        width: 450,
        // height: 380,
        closed: true,
        onOpen: function() {
            $('#Add').parent().css("left", "25%");
            $('#Add').parent().next().css("left", "25%");
            $('#Add').parent().next().css("top", "25%");
            $('#Add').parent().css("top", "25%");
        }
    });
    JSUtility.window_edit_title = "项目人员";
    JSUtility.window_edit_form = $("#Add").find("form");
    $('#Add').show();
    ComboboxInitial();
});

function ComboboxInitial() {
    JSHelper.comboboxData("#UserRole", "10");
    JSHelper.comboboxData("#UserField", "7");
    if (!self.parent.projectInfoManager) {
        // $("#ProjectId").attr("Class", "easyui-combotree");
        JSHelper.combotreeProject('ProjectId', null, 205);
    }
    //    $("#ProjectId").combotree({
    //        url: "../Handler/AjaxProjectTreeHandle.ashx"  
    //    });
    //    //$("#ProjectId").attr("validtype", "projectNumAjax[0]");  //validtype="projectNumAjax[0]"
    //    $("#ProjectId").combotree("tree").tree({
    //        onClick: function(node) {
    //            if (node.attributes == null || node.attributes == 'undefined') {
    //                // $.messager.alert('系统提示', '此项不可选', 'info');
    //                $("#ProjectId").combotree("setValue", null);
    //                $("#ProjectId").combotree("setText", null);
    //            } else {
    //                $("#ProjectId").combotree("setValue", node.attributes["ProjectNum"]);
    //                $("#ProjectId").combotree("setText", node.text);
    //                $("#ProjectId").combotree("hidePanel");
    //            }
    //        }
    //    });
}

function Initlist(size) {
    if (self.parent.projectInfoManager) {
        JSUtility.param.Options["ProjectId"] = self.parent.parent.project_id;
        JSUtility.replenish = function() {
            $("#ProjectId").val(self.parent.parent.project_id);
        };
        $("#ProjectId").attr("readonly", "readonly");
    }
    JSUtility.param.Method = "Search";
    JSUtility.grid = $('#Grid').datagrid({
        tilte: '项目人员信息',
        iconCls: 'icon-save',
        width: size.width,
        height: size.height,
        pageSize: Math.round(size.height / 25),
        pageList: [Math.round(size.height / 25)],
        nowrap: true,
        striped: true,
        url: JSUtility.url,
        queryParams: { "json": $.toJSON(JSUtility.param) },
        sortName: 'Id',
        sortOrder: 'desc',
        idField: 'Id',
        frozenColumns: [[{ title: '编号', field: 'Id', width: 50, sortable: true}]],
        columns: [[
                            { title: '项目编号', field: 'ProjectId', width: 80 },
                            { title: '项目名称', field: 'ProjectName', width: 100 },
                            { title: '员工编号', field: 'EmployeeId', width: 80 },
                            { title: '员工姓名', field: 'EmployeeName', width: 80 },
                            { title: '项目角色', field: 'UserRole', width: 80 },
                            { title: '专业名称', field: 'UserField', width: 80 },
                            { title: '任命时间', field: 'AppointTime', width: 80 },
                            { title: '任命机构', field: 'AppintOrganization', width: 80 },
                            { title: '任免时间', field: 'RemoveTime', width: 80 },
                            { title: '任免机构', field: 'RemoveOrganization', width: 80 },
                            { title: '是否在职', field: 'IsValid', width: 80 },
                            { title: '非本院人员备注', field: 'EmployeeAnnotations', width: 150 },
                            { title: '创建时间', field: 'CreateTime', width: 80 }


                        ]],
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        toolbar: [
                    {
                        text: '添加',
                        iconCls: 'icon-add',
                        handler: function() {
                            JSUtility.add();
                            $("#IsValid").combobox("setValue", "在职");
                        }
                    }, '-',
                    {
                        text: '修改',
                        iconCls: 'icon-edit',
                        handler: function() {
                            JSUtility.update();
                            //                            $("#ProjectId").combotree("setValue", JSUtility.row.ProjectId);
                            //                            $("#ProjectId").combotree("setText", JSUtility.row.ProjectName);
                            JSHelper.conbotreeUpdateProject("ProjectId");
                        }
                    }, '-',
                    {
                        text: '删除',
                        iconCls: 'icon-remove',
                        handler: JSUtility.del
                    }, '-',
                    {
                        text: '查询',
                        iconCls: 'icon-search',
                        handler: JSUtility.search
                    }
                  ]
    });
}
